﻿CREATE PROCEDURE dbo.procCreateInnerException
	@ParentID int,
	@ExceptionID char(49),
	@Message nVarChar(500),
	@Source nVarChar(250),
	@StackTrace nVarChar(MAX),
	@TargetSite nVarChar(250),
	@InnerExceptionID int OUTPUT
AS

/****************************************************************************************************
 **        Name: procCreateInnerException
 ** Description: Creates a new InnerException record.
 ****************************************************************************************************
 ** Revisions
 **  Date        Author               Work Item  Description
 **  ----------  -------------------  ---------  ----------------------------------------------------
 **  11/30/2008  Chad Green             11774    Initial Development
 **  02/21/2009  Chad Green             11774    Added the InnerExceptionID output parameter and no longer returning the SCOPE_IDENTITY.
 ****************************************************************************************************/



BEGIN TRY

	-- Create the new record
	IF EXISTS(SELECT * FROM InnerException WHERE ID = @ParentID)
		BEGIN
			INSERT INTO InnerException (ParentID,
																	ExceptionID,
																	Message,
																	Source,
																	StackTrace,
																	TargetSite)
													VALUES (@ParentID,
																	@ExceptionID,
																	@Message,
																	@Source,
																	@StackTrace,
																	@TargetSite)
		END
	ELSE
		BEGIN
			INSERT INTO InnerException (ParentID,
																	ExceptionID,
																	Message,
																	Source,
																	StackTrace,
																	TargetSite)
													VALUES (NULL,
																	@ExceptionID,
																	@Message,
																	@Source,
																	@StackTrace,
																	@TargetSite)
		END

	-- Return the record identifier
	SET @InnerExceptionID = @@IDENTITY

END TRY
BEGIN CATCH
	EXEC procCreateSQLErrorLog
END CATCH
GO

EXEC sp_addextendedproperty @name='MS_Descritpion', @value ='Creates a new InnerException record.', @level0type = 'SCHEMA', @level0name = 'dbo', @level1type = 'PROCEDURE', @level1name = 'procCreateInnerException', @level2type = NULL, @level2name = NULL
GO